$(function () {
    let login=$('.login-btn');
    login.click(function (e) {
        e.preventDefault();
        let account=$('input[name=account]').val();
        let password=$('input[name=password]').val();
        if(account===''){
            message.showError("账号不能为空");
            return
        }

        if(!(/^\w{5,20}$/).test(account) && (!(/^1[3-9]\d{9}$/))){
            message.showError("账号格式不正确");
            return
        }
         if(password===''){
            message.showError("密码不能为空");
            return
        }
        let remember = $('input[name="remember"]').is(':checked');
        $.ajax({
            url:"/user/login/",
            type:"POST",
            dataType:"json",
            data:{
                account:account,
                password:password,
                remember:remember,
            },
            success:function (date) {
                if(date.errno ==='0') {
                    message.showSuccess("恭喜你登录成功");
                    setTimeout(function () {
                        window.location.href = "/"
                    }, 1000)
                }
                else
                    {
                        message.showError(date.errmsg)
                    }
            },

        })
    })
});